import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Times {
	Connection con = Jdbc_Factory.getConnection();

	public static void main(String[] args) throws SQLException {

		Times dao = new Times();

	    dao.insert();
		dao.select();
	}

	public void insert() {

		try {
			String sql = "INSERT INTO TIMES VALUES(S_DEC.nextval,to_date(?,'yyyy-mm-dd HH24:mi:ss'))";
			PreparedStatement pst = con.prepareStatement(sql);
			Date date = new Date();
			String st = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
					.format(date);
			pst.setString(1, st);
			pst.executeUpdate();
			con.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void select() throws SQLException {
		String sql = "select * from TIMES";
		PreparedStatement pst = con.prepareStatement(sql);
		ResultSet rs = pst.executeQuery();
		while (rs.next()) {
			System.out.println("time=" + rs.getString("time")+"       ID="+rs.getInt("id"));
		}
		con.commit();
		pst.close();
		con.close();
	}

	public void empty(String table) throws SQLException {
		String sql = "truncate table " + table;
		PreparedStatement pst = con.prepareStatement(sql);
		pst.executeUpdate();
	}
}
